package com.base.cn.platform.os.controller.op.coupon;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.service.manage.op.coupon.OpCouponCodeService;
import com.base.cn.platform.os.service.manage.op.coupon.OpCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 优惠券
 * @author ll
 * @date 2018/5/14 11:39
 */
@Controller
@RequestMapping("/admin/op/coupon")
public class AdminOpCouponCodeController extends AdminBaseController {


    @Autowired
    private OpCouponCodeService opCouponCodeService;
    @Autowired
    private OpCouponService opCouponService;
    /**
     * 翻页搜索优惠券编码
     * @param opCouponCode
     * @param currentPage
     * @return
     */
    @RequestMapping("/queryOpCouponCodeListPage")
    public String queryOpCouponCodeListPage(Model model,
                                                 @RequestBody Map<String, Object> opCouponCode,
                                                 @RequestParam(value = "currentPage",required = false,defaultValue = "1")Integer currentPage){
        Map<String,Object> dataMap =opCouponCodeService.queryOpCouponCodeListPage(opCouponCode,currentPage,true,true);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/op/coupon/coupon_code_ajax_list");
    }

    /**
     * 导出优惠券
     * @param couponId 优惠券ID
     * @param status 优惠券状态
     * @return
     * @throws IOException
     */
    @OpLog(module = AdminModuleEnum.OTHER, action = "导出优惠券")
    @RequestMapping("/downloadExcelOpCouponCodeList")
    public ResponseEntity<byte[]> downloadExcelOpCoupon( @RequestParam(value = "couponId") BigDecimal couponId,@RequestParam(value = "status",required = false) Integer status,@RequestParam(value = "beginUseTime", required = false) String beginUseTime,@RequestParam(value = "endUseTime", required = false) String endUseTime) throws IOException {
       Map<String,Object> params  = new HashMap<>();
        params.put("couponId",couponId);
        params.put("status",status);
        params.put("beginUseTime",beginUseTime);
        params.put("endUseTime",endUseTime);
        return opCouponService.downloadExcelOpCoupon(params);
    }


}
